<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #canvas {
            border: 1px solid #333;
        }
    </style>
</head>

<body>
    <canvas id="canvas" width="200" height="200"></canvas>
    <script>
        /* 1、画布 */
        var canvas = document.getElementById("canvas");
        /* 2、context */
        var ctx = canvas.getContext("2d");
        let increase = true;
        let smallIn = 20, smallOut = 50, bigIn = 40, bigOut = 80
        let smallRadius = smallIn, bigRsdius = bigIn
        /* 
        smallIn~smallOut
        <smallIn   true  radius ++
        >smallOut   false radius --
        */
        /*
        50~80
        <bigIn   true  radius ++
        >bigOut   false radius --
         */
        function draw() {
            /* 清空画布 */
            ctx.clearRect(0, 0, canvas.width, canvas.height)
            /* 外圆 */
            ctx.beginPath()
            ctx.arc(100, 100, bigRsdius, 0, Math.PI * 2)
            ctx.closePath();
            ctx.fillStyle = "#ff2d51"
            ctx.fill();
            /* 内圆 */
            ctx.beginPath()
            ctx.arc(100, 100, smallRadius, 0, Math.PI * 2)
            ctx.closePath();
            ctx.fillStyle = "#1248F8"
            ctx.fill();
            if (bigRsdius > bigOut) {
                increase = false;
            } else if (bigRsdius < bigIn) {
                increase = true;
            }
            let smallStep = (smallOut - smallIn) / (bigOut - bigIn)
            if (increase) {
                bigRsdius++;
                smallRadius += smallStep;
            } else {
                bigRsdius--;
                smallRadius -= smallStep;
            }
            setTimeout(draw, 30)
        }
        draw();
    </script>
</body>

</html>